package com.ls.blog.controller;

/**
 * @program: myblog
 * @author: lishun
 * @create: 2021-07-10 16:59
 **/

import com.ls.blog.annotation.LogAnnotation;
import com.ls.blog.result.JsonResult;
import com.ls.blog.api.CommentsService;
import com.ls.blog.result.ResultCode;
import com.ls.blog.utils.ResultTool;
import com.ls.blog.vo.CommentsVo;
import com.ls.blog.vo.params.CommentParam;
import com.ls.blog.vo.params.CommentsParam;
import com.qiniu.util.Json;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 评论controller
 */
@Api(tags = {"评论模块"})
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 评论信息显示
     * @throws Exception
     */
    @ApiOperation("获得评论")
    @LogAnnotation(module = "评论模块",operation = "根据文章id获得评论信息")
    @GetMapping("article")
    public JsonResult<Map<String,Object>> showComments(CommentsParam param) throws Exception {
        System.out.println(param);
        Map<String, Object> map = commentsService.showComments(param);
        return ResultTool.success(map);
    }

    @ApiOperation("/回复分页显示")
    @LogAnnotation(module = "评论模块",operation = "分页显示回复")
    @GetMapping("replies/{id}")
    public JsonResult<List<CommentsVo>> replyComments(@PathVariable("id") Long id, Long current) throws Exception {
        return ResultTool.success(commentsService.secondComments(id,current));
    }

    /**
     * 评论
     * @param commentParam
     * @return
     */
    @ApiOperation("评论功能")
    @LogAnnotation(module = "评论模块",operation = "评论")
    @PostMapping("/create")
    public JsonResult comment(@RequestBody() CommentParam commentParam){
        System.out.println(commentParam);
        commentsService.comment(commentParam);
        return ResultTool.success(ResultCode.COMMENT_SUCCESS);
    }






}
